<?php
/**
* @package      auto_occasion
* @subpackage   annonce
* @author       CMS
* @copyright    2011
* @license      All rights reserved
*/

class BoMailCtrl extends jController {

    
    public $pluginParams = array(
                                    '*'=>array('auth.required'=>true,
                                    'jacl2.right'=>'admin.compte.gerer'
                                    )
                            );


    /**
    * Affiche la page de liste des mail
    */
    function index() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_ANNONCES ;

		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jconfirmaction.jquery.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jconfirmaction.jquery.ask.js');


        jClasses::inc('commun~common');
        $liste = common::liste('ao_mail_templates');

        $rep->bodyTpl = 'annonce~BoMailList';
        
        $rep->body->assign('liste', $liste);

        return $rep;
    }

    /**
    * Edition / ajout d'un mail
    */
    function editer() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_ANNONCES ;
        
   		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jquery.validation.js');

        jClasses::inc('commun~common');


        $id  = $this->param('id', '');

        $mail   = ($id) ? common::chargeParId($id, 'ao_mail_templates') : common::init('ao_mail_templates');

        $rep->body->assign('mail', $mail);

        $rep->bodyTpl = 'annonce~BoMailEdit';
        
        return $rep;
    }

    /**
    * Sauvegarder un mail
    */
    function sauvegarder() {
        $rep = $this->getResponse('redirect');
        
        jClasses::inc('annonce~mailSrv');

        $mail               = new stdClass();
        $mail->mail_name    = $this->stringParam('mail_name', '');
        $mail->mail_content = $this->param('contenu', '');
        $mail->mail_status  = $this->intParam('status', 0);
        $mail->mail_id      = $this->intParam('id', 0);

        if ($mail->mail_id) {
            mailSrv::modifier($mail);
        } else {
            mailSrv::ajouter($mail);
        }
        
        $rep->action = 'annonce~BoMail:index';

        return $rep;
    }

    /**
    * Supprime un mail
    */
    function supprimer() {
        $rep = $this->getResponse('redirect');
        jClasses::inc('commun~common');

        $id = $this->stringParam('id');
        common::supprimer($id, 'ao_mail_templates');

        $rep->action = 'annonce~BoMail:index';

        return $rep;
    }

}